package com.rtx.wms.std.ctclass;

import java.util.Map;

import com.rtx.edi.model.api.bo.ApiMappingInfoBo;

public class EdiDynamicsHelp {

	/**
	 * 创建对象
	 * @param config 全局配置
	 * @param clazz 找不到类时 生成对象的类
	 * @param cacheKey 缓存class类的名称
	 * @return
	 */
    public static Object createObjectByConfig(ApiMappingInfoBo config,Class clazz,String cacheKey){
    	Object head = null;
    	try {
    		Long apiid =  config.getTargetApi().getId();
    		Map<String,Class> map = ClassHolder.apiconfigClassMap.get(apiid+"");
    		if(map != null) {
    			Class headclass =map.get(cacheKey);
    			head = headclass.newInstance();
    		}else {
    			head = clazz.newInstance();
    		}
    	} catch (Exception e) {
    		try {
    			head = clazz.newInstance();
			} catch (Exception e2) {
			}
    		
    	}

    	return head;
    }
}
